$(document).ready(function(){
    //validate cac form
    $('.validate-form').validate();
    
    //////////////////////////////////////////////
    //CHECK ALL
    //check all in table 
    $('.check-all').click(function(){
        $checkAll = $(this).attr('checked');
        $('.sub-check').each(function(){
            $subCheck = $(this).attr('checked');
            if($checkAll !=$subCheck ) $(this).click();    
        }); 
    });
    
    //check trong Exame table
    $('.check-all-choose').click(function(){
        $checkAll = $(this).attr('checked');
        $('.sub-check-choose').each(function(){
            $subCheck = $(this).attr('checked');
            if($checkAll !=$subCheck ) $(this).click();    
        }); 
    });
    
    //
    // === HIDE MENU UTIL CLICK
    //$('.submenu:not(:first)').hide();
    //
    // === SLIDE UP - SLIDE DOWN MENU
    $('.menu_sup').click(function(){
    	$(this).next('.submenu').slideToggle(500);        
    });
    
    //
    // === Slide up - Slidup Quiz - addquestion
    $('.quiz-title').click(function(){
    	$(this).next('form').slideToggle(1500);
    });
    ///////////////////////////////////////////////
    //an chuc nang sua xoa trong cac bang du lieu 
    $('.row_action').hide();
    $('.post_title').hover(function(){
        $(this).children('div').slideDown(100);
    },function(){
        $(this).children('div').hide();
    });
    
    //
    // === Tabs
    $( "#tabs" ).tabs().find( ".ui-tabs-nav" ).sortable({ axis: "x" });
    
    //
    // === Slide Toggle cac Dap an khi add new question
    $('#txtD_parent, #txtE_parent').hide();
    $('.zend_form dt').click(function(){
    	$(this).next('dd').children('span').slideToggle(500);
        $(this).next('dd').css('min-height','30px');
    });
    
    /** IMPORT FILE CUA MENU USER */
    
    $('.cBtImport').click(function(){
        $('.import').slideToggle(400);  
    });
    
    /* XUAT NHAP FILE - TABLE NAV - LOP */
    $('a.tab').click(function(){
        $('.active').removeClass('active');
        $(this).addClass('active');
        $('.content').slideUp();
        var content_show = $(this).attr('title');
        $('#'+ content_show).slideDown();
        
    });
    
    //
    //quiz add new
    //date picker
    jQuery.datepicker.setDefaults( jQuery.datepicker.regional[ "" ] );
    $('#txtDateStartD').datepicker(jQuery.datepicker.regional[ "vi" ]);
    $('#txtDateEndD').datepicker($.datepicker.regional[ "vi" ]);
    $('#birthday').datepicker($.datepicker.regional[ "vi" ]); //user controller
    
    //
    //KHO DICH CHUYEN TRANG KHI SUBMIT
//    $('.submit').click(function(){
//    	return false;
//    })

    //
    //SUP MENU IN BACKEND
    $('.selectSupMenu').change(function(){        
       $action = $(this).children('option:selected').attr('value');
       window.location.href = baseUrl($action);        
    });     
       
    // BANG DIEM
    //chon khoa hoc
    $('.lop-list-khoa').change(function(){  
        var khoa = $(this).children('option:selected').attr('value');
        
       // $('#maincontent').load('http://localhost/quiz/public/admin/mark/?cmdFilter-khoa=Lá»�c&cbbKhoa='+khoa);
        
        //return false;
        /*$.ajax({
            type: 'GET',
            dataType: 'json',
            url     : 'http://localhost/quiz/public/admin/mark',
            async   : false,
            data    : {cbbKhoa: khoa,'cmdFilter-khoa': 'loc'}
                
        });
        return false;
        
    */ 
         
    });    
    
    
 
    ///////////////////////////////////////////////////////
    // CREATE FUNCTION
    ///////////////////////////////////////////////////////
    var baseUrl = function(moduleAction){        
        $url = window.location.pathname.split('/');
        $host = window.location.hostname;
        $baseUrl = "http://"+$host+ "/" + $url[1] + "/" + $url[2] + "/" + moduleAction + "/" ;
        return $baseUrl;
    };
    
    /**
    * kiem tra 1 phan tu trong mang
    * return Bool
    */
    var in_array = function(valueCheck,arrayCheck){
        for(x in arrayCheck) {
            alert(arrayCheck[x]);
            if (arrayCheck[x] ==valueCheck){
                
                //return true;
            }
        }
        return false;
    }
});
